var usedata = require("../shoppingCartdata/shoppingCartdata.js");
var usedata2 = require("../addressdata/addressdata.js");
var detailsData = require("../detailsdata/detailsdata.js");
const jisuan = require('../../utils/jisuan.js');
var indexData = require("../indexdata/indexdata.js");
Page({
  data: {
    address: "",//地址
    count: "",
    countSum:"170.00",
    cashCouponText:"10.00",//代金券金额
    cashCouponText2: "10.00",//代金券金额
    cashCouponText3: "0",
    cashCouponText4: "10.00",//代金券金额
    cardTextNum: "12.00",//体验卡
    cardTextNum2: "0",//体验卡
    cardText: "0.00",
    hasList: true,
    selectAllStatus: true, // 全选状态，默认全选
    cardBtn:false,
    cardHidden:true,
    cardWrapHidden:true,
    productNumber:3,
    shoppingNumber:"3",
    // vouchers: "",//20200214代金券
    // giftPrice1: '',//代金券序列号
    giftPrice2: '',//默认代金券序列号
    cashCouponTextVal: "",//代金券内容
    giftBtn: false,//代金券默认开关
    giftImgBtn:false,//代金券true or文字false开关
    discountBtn: true, //是否有优惠券
    noAddressHeight:true,//20200309是否有地址
    addressSelectBtn: true,//选择地址显示隐藏，true隐藏
    addressAll: "",
    addressSelect: "",
    addressText: "",
    addressTextPs: '',//配送地址
    //提交订单
    model: '',
    /**
     * dn:mints(n,-1,-2),jsmodel(JINE，TIANSHU),isjzrq(选择截止日期),pstype(0同送，1轮送),
     * zhouqi(0天天订，1单双日订，2周一至周五，3周末订)
     * Count,qdrq,tdrq,jgts,dsj,TotalDays,TotalCount,je,
     * xq1,xq2,xq3,xq4,xq5,xq6,xq7
     */
    dn: {
      mints: 0,
      ishuodong: false,
      ists: true,
      isksrq: false,
      isjzrq: false,
      pstype: "0",
      zhouqi: "0",
      Count: 1,
      qdrq: "",
      tdrq: "",
      snsd: 2,
      jgts: 0,
      dsj: 0,
      TotalDays: 0,
      TotalCount: 0,
      je: 0,
      xq1: 0,
      xq2: 0,
      xq3: 0,
      xq4: 0,
      xq5: 0,
      xq6: 0,
      xq7: 0,
      onsale: "", //选择的活动项
      dnmodel: ""
    },
    dnTs: "", //选择订奶天数
    milkingSelectDay: "",
    zhouqiSelect: 0,
    psrqSelect: false,
    milkingTimer: "", //送奶时间
    // snsd: "",
    syspars: "", //系统参数
    onsaleinfo: "", //活动,20200214代金券
    onsaleselected: "", //选择的活动项
    shoppingcart: true,
    showModalStatusShare: false,
    deliveryMethod: '',//配送方式20200427
    deliveryMethodSelect: '',//20200427
    historicalOrders: '',//历史订单20200427
    text: '您今天的配送：鲜奶1瓶，尚有1瓶带配送，订单预计截止日期为2020-09-08',
    marqueePace: 0.8,//滚动速度
    marqueeDistance:0.8,//初始滚动距离
    marqueeDistance2: 0.8,
    marquee2copy_status: false,
    marquee2_margin: 0,
    size: 14,
    orientation: 'left',//滚动方向
    interval: 20, // 时间间隔
    formSumbitBtn: true,//是否true有确认订单
    formSumbitHidden: true,//表单false显示true隐藏
    formGouwuche: true,//加入购物车true,直接购买false
    modeBorderClick: true,//到期提醒true隐藏，显示隐藏
    productSelectSp_image:'',//选择产品
    productSelectSp_name:'',
    productSelectSp_price:'',
    tuijianData: '',//推荐日期选择
    tuijianDataIndex: '',//推荐日期下标
    tabBar: indexData.tabBar,//tabar
    
  },
  staticData: {//验证码提交
  },
  onLoad: function (options) {
    // wx.setTabBarBadge({//购物车数量
    //   index:1,
    //   text: this.data.shoppingNumber
    // })
    this.setData({
      count: usedata.setdata,
      address: usedata.address,
      vouchers: usedata.vouchers,
      giftPrice1: usedata.vouchers[0].giftPrice,   
      // 20200214
      vouchers: usedata.vouchers,
      giftPrice2: usedata.vouchers[0].giftPriceNum,
      cashCouponTextVal: usedata.vouchers[0].giftPriceText,   
      // 20201204选择地址
      addressAll: usedata2.address,
      addressSelectText: usedata2.address[0].index,
      addressTextPs: usedata2.address[0].address,      
        // 订单
      // spinfo: spinfo,
      spinfo: detailsData.spinfo,
      syspars: detailsData.spinfo.syspars,
      dnTs: detailsData.spinfo.dnTs,
      // 'dn.dsj': spinfo.price,
      // 'dn.mints': spinfo.syspars.mints,
      // 'dn.TotalDays': Number(spinfo.syspars.mints),
      // 'dn.qdrq': spinfo.syspars.minksrq,
      // //推荐消息， 订奶列表数据
      // imgUrls: [spinfo.sp.productImg, spinfo.sp.productImg, spinfo.sp.productImg],
      // specification: spinfo,
      commodityDetails: detailsData.commodityDetails,
      commodityDetailsImg: detailsData.commodityDetailsImg,
      // dnTs: util.dnTs,
      model: detailsData.spinfo.model,
      // milkingSelectDay: spinfo.syspars.mints > 1 ? util.dnTs[0].milkingDay : 1,
      // 'dn.dnmodel': dnmodel[0],
      // 'dn.zhouqi': dnmodel[0].zhouqi,
      // zhouqiSelect: Number(dnmodel[0].zhouqi),
      imgUrls: detailsData.imgUrls,
      dnmodel_note: detailsData.spinfo.dnmodel_note,
      onsale_note: detailsData.spinfo.onsale_note,
      specification: detailsData.specification,
      // commodityDetails: detailsData.commodityDetails,
      // commodityDetailsImg: detailsData.commodityDetailsImg,
      // milkingArr: detailsData.milkingArr,
      milkingTimer: detailsData.milkingTimer,
      milkingTimerText: detailsData.milkingTimer[0],
      milkingSelectDay: detailsData.spinfo.dnTs[0].milkingDay,
      // vouchers: detailsData.vouchers,
      // giftPrice1: detailsData.vouchers[0].giftPrice,  
      // 20200219产品规格
      selectionCapacity: detailsData.selectionCapacity,
      // capacitySelect: spinfo.sp.spid,     
      spellList: detailsData.spellList, //20200310拼单
      deliveryMethod: detailsData.deliveryMethod,//20200427配送方式
      deliveryMethodSelect: detailsData.deliveryMethod[0].deliveryMethod,
      historicalOrders: detailsData.historicalOrders,     
      // 20210311推荐日期
      tuijianData: detailsData.tuijianData,
      tuijianDataIndex: detailsData.tuijianData[0].tuijianDataIndex,   
      tabBar: indexData.tabBar,//tabar
    })
  },
  onReady: function () {
    // tabar选中状态
    var tabBar = this.data.tabBar;
    tabBar[0].select = false;
    tabBar[1].select = false;
    tabBar[2].select = true;
    tabBar[3].select = false;
    this.setData({
      tabBar: tabBar
    })
  },  
  onShow: function (e) {
    // 页面显示
    // var vm = this;
    // var length = vm.data.text.length * vm.data.size;//文字长度
    // var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕宽度
    // vm.setData({
    //   length: length,
    //   windowWidth: windowWidth,
    //   marquee2_margin: length < windowWidth ? windowWidth - length : vm.data.marquee2_margin//当文字长度小于屏幕长度时，需要增加补白
    // });
    // vm.run1();// 水平一行字滚动完了再按照原来的方向滚动
    // vm.run2();// 第一个字消失后立即从右边出现
  },
  run1: function () {
    var vm = this;
    var interval = setInterval(function () {
      if (-vm.data.marqueeDistance < vm.data.length) {
        vm.setData({
          marqueeDistance: vm.data.marqueeDistance - vm.data.marqueePace,
        });
      } else {
        clearInterval(interval);
        vm.setData({
          marqueeDistance: vm.data.windowWidth
        });
        vm.run1();
      }
    }, vm.data.interval);
  },
  run2: function () {
    var vm = this;
    var interval = setInterval(function () {
      if (-vm.data.marqueeDistance2 < vm.data.length) {
        // 如果文字滚动到出现marquee2_margin=30px的白边，就接着显示
        vm.setData({
          marqueeDistance2: vm.data.marqueeDistance2 - vm.data.marqueePace,
          marquee2copy_status: vm.data.length + vm.data.marqueeDistance2 <= vm.data.windowWidth + vm.data.marquee2_margin,
        });
      } else {
        if (-vm.data.marqueeDistance2 >= vm.data.marquee2_margin) { // 当第二条文字滚动到最左边时
          vm.setData({
            marqueeDistance2: vm.data.marquee2_margin // 直接重新滚动
          });
          clearInterval(interval);
          vm.run2();
        } else {
          clearInterval(interval);
          vm.setData({
            marqueeDistance2: -vm.data.windowWidth
          });
          vm.run2();
        }
      }
    }, vm.data.interval);
  },  
  add: function (e) {
    // 加
    var count = this.data.count;
    var index = e.currentTarget.dataset.index;
    count[index].num++;
    count[index].price = (count[index].num * count[index].danjia * count[index].day).toFixed(2);
    this.setData({
      count: count
    });

    this.countSum()
  },
  minus: function (e) {
    // 减
    var count = this.data.count;
    var index = e.currentTarget.dataset.index;
    if (count[index].num <= 1) {
      count[index].num = 1
    } else {
      count[index].num--;
    }
    count[index].price = (count[index].num * count[index].danjia * count[index].day).toFixed(2);
    this.setData({
      count: count
    })
    this.countSum()
  },
  remove: function (e) {
    // 删除
    var count = this.data.count;
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确认删除吗？',
      success: function (res) {
        if (res.confirm) {
          // console.log('用户点击确定')
          // 获取要删除数据的id 
          var index = e.currentTarget.dataset.index;
          // 删除数组对应的数据内容 
          var release = count;
          count.splice(index, 1)
          //判断数据的长度 
          var len = count.length;
          //通过判断数组的长度来决定是否显示隐藏的部分 
          // console.log(count)
          that.setData({
            count: count
          });
          // 如果数据为空
          if (!count.length) {
            that.setData({
              hasList: false
            });
            that.countSum()
          } else {
            // 调用金额渲染数据
            that.countSum()
          }
        } else if (res.cancel) {
          console.log('用户点击取消删除')
        }
      }

    })
  },
  countSum: function () {
    // 总价
    var count = this.data.count;
    var countSum = 0;
    var productNumber = []
    for (var i = 0; i < count.length; i++) {
      // 判断选中计算价格
      if (count[i].checked) {
      //   // 所有价格加起来 count_money
        countSum += Number(count[i].price);
        productNumber.push(count[i])
        
      }
    }
    if (countSum > 0) {
      countSum = countSum - this.data.cashCouponText2 - this.data.cardText;
      if (countSum < 0) {
        countSum = 0
      }
    } else {
      countSum = countSum
    }
    this.setData({
      countSum: countSum.toFixed(2),
      productNumber: productNumber.length
    })
    
  }, 
  selectList(e) {
    // 当前商品选中事件
    var that = this;
    // 获取选中的radio索引
    var index = e.currentTarget.dataset.index;
    // 获取到商品列表数据
    var count = that.data.count;
    // 默认全选
    that.data.selectAllStatus = true;
    // 循环数组数据，判断----选中/未选中[checked]
    count[index].checked = !count[index].checked;
    // 如果数组数据全部为checked[true],全选
    for (var i = count.length - 1; i >= 0; i--) {
      if (!count[i].checked) {
        that.data.selectAllStatus = false;
        break;
      }
    }
    // 重新渲染数据
    that.setData({
      count: count,
      selectAllStatus: that.data.selectAllStatus
    })
    console.log(this.data.selectAllStatus)
    // 调用计算金额方法
    that.countSum();
  },
  selectAll(e) {
    // 购物车全选事件
    // 全选ICON默认选中
    let selectAllStatus = this.data.selectAllStatus;
    // true  -----   false
    selectAllStatus = !selectAllStatus;
    // 获取商品数据
    let count = this.data.count;
    // 循环遍历判断列表中的数据是否选中
    for (let i = 0; i < count.length; i++) {
      count[i].checked = selectAllStatus;
    }
    // 页面重新渲染
    this.setData({
      selectAllStatus: selectAllStatus,
      count: count
    });
    // 计算金额方法
    this.countSum();
  },
  cardWrapHidden(){//体验卡账号显示
    var cardWrapHidden = this.data.cardWrapHidden;
    cardWrapHidden = !this.data.cardWrapHidden;
    this.setData({
      cardWrapHidden: cardWrapHidden
    });    
  },
  accountChange(e) {//账号监听
    this.staticData.accountChange = e.detail.value;
  },
  passwordtChange(e) {//账号监听
    this.staticData.passwordChange = e.detail.value;
  },  
  cardSubmit:function(){//验证码提交
    if (!this.staticData.accountChange) {
      wx.showToast({
        title: '请输入账号',
        icon: 'loading',
        // image:'../images/details/1.png',
        duration: 500
      })
      return;
    }
    if (!this.staticData.passwordChange) {
      wx.showToast({
        title: '请输入密码',
        icon: 'loading',
        duration: 500
      })
      return;
    }
    this.setData({
      cardBtn:true,
      cardHidden:false,
      cardText:this.data.cardTextNum,
      cashCouponText2: this.data.cashCouponText3,
      cashCouponTextVal: this.data.cashCouponText3,
      cardWrapHidden: true
    });    
    this.countSum()
  },
  changeSwitch: function () {//是否使用体验卡
    var changedData = this.data.cardBtn;
    changedData = !this.data.cardBtn;
    if (changedData) {
      this.setData({
        cardText: this.data.cardTextNum,
        cashCouponText2: this.data.cashCouponText3,
        cashCouponTextVal: this.data.cashCouponText3
      });

    } else {
      this.setData({
        cardText: this.data.cardTextNum2,
        cashCouponText2: this.data.vouchers[this.data.giftPrice2].giftPriceVal,
        cashCouponTextVal: this.data.vouchers[this.data.giftPrice2].giftPriceText,
        giftBtn: false,
        giftPrice1: this.data.giftPrice2
      })
    }
    this.setData({
      cardBtn: changedData
    });
    this.countSum()
  },
  vouchersRadio: function (e) {//选择代金券
    console.log('radio发生change事件，携带的value值为：', e.detail.value)
    if (!this.data.cardBtn) {
      this.setData({
        giftPrice1: e.detail.value,
        // cashCouponText: e.detail.value,
        cashCouponText4: e.detail.value,
        // cashCouponText2: e.detail.value,
      })
    } else {
      this.setData({
        giftPrice1: e.detail.value,
        // cashCouponText: e.detail.value,
        cashCouponText4: e.detail.value,
        // cashCouponText2: this.data.cashCouponText3
      })
    }
    // this.countSum()

  },
  giftSelectBtn: function () {//确认代金券金额
    if (!this.data.cardBtn) {
      this.setData({
        giftBtn: true
      })
      if (this.data.giftBtn) {
        this.setData({
          giftPrice2: this.data.giftPrice1,
          cashCouponText: this.data.cashCouponText4,
          cashCouponText2: this.data.vouchers[this.data.giftPrice1].giftPriceVal,
          cashCouponTextVal: this.data.vouchers[this.data.giftPrice1].giftPriceText,
        })
      }
    } else {
      this.setData({
        giftPrice2: this.data.cashCouponText4,
        cashCouponText: this.data.cashCouponText4,
        cashCouponText2: this.data.cashCouponText3,
        cashCouponTextVal: this.data.cashCouponText3,
      })
    }
    // this.countSum();
    this.hideModal();
  },
  //点击我显示优惠券弹出框
  clickme1: function () {
    this.setData({
      giftBtn: false,
      giftPrice1: this.data.giftPrice2
    })
    this.showModal();
  },
  //显示对话框
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  //隐藏对话框
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
    this.setData({
      giftPrice1: this.data.cashCouponText4,
    })  
  },
  goDetails: function (event) {
    var newsid = event.currentTarget.dataset.newsid;
    wx.navigateTo({
      url: '../payDetails/payDetails?newsid=' + newsid
      // 跳转到商品详情
    })
  },
  goAddress:function(){//跳转地址页面
    wx.navigateTo({
      url: '../address/address' 
    })
  },
  goCashCoupon:function(){//跳转到代金券页面
    wx.navigateTo({
      url: '../cashCoupon/cashCoupon'
    })    
  },
  goZhiFu: function () {//跳转到支付
    wx.navigateTo({
      url: '../pay/pay'
    })
  },
  addressRadio: function (e) {//选择默认地址
    console.log('radio发生change事件，携带的value值为：', e.detail.value)
    var count = this.data.addressAll;
    var addressShop = this.data.address
    var index = e.detail.value;
    addressShop.name= count[index].name;
    addressShop.tel= count[index].tel;
    addressShop.address = count[index].address;
    this.setData({
      addressSelectText: e.detail.value,
      address: addressShop,
    })
  },
  addressRadio2: function (e) {//选择地址
    var count = this.data.addressAll;
    var index = e.currentTarget.dataset.index;
    var addressShop = this.data.address
    addressShop.name = count[index].name;
    addressShop.tel = count[index].tel;
    addressShop.address = count[index].address;
    this.setData({
      address: addressShop,
      addressSelectBtn: true
    })
  },

  remove: function (e) {
    // 删除
    var count = this.data.addressAll;
    var that = this;
    var mrAddress = that.data.addressSelectText
    wx.showModal({
      title: '提示',
      content: '确认删除吗？',
      success: function (res) {
        if (res.confirm) {
          // console.log('用户点击确定')
          // 获取要删除数据的id 
          var index = e.currentTarget.dataset.index;
          // 删除数组对应的数据内容 
          var release = count;
          // 获取选中的radio索引
          count.splice(index, 1)


          //判断数据的长度 
          var len = count.length;
          //通过判断数组的长度来决定是否显示隐藏的部分 
          // console.log(count)
          that.setData({
            addressAll: count
          });
        } else if (res.cancel) {
          console.log('用户点击取消删除')
        }
      }

    })
  },
  goEditAddressId: function (event) {
    var newsid = event.currentTarget.dataset.newsid;
    wx.navigateTo({
      url: '../editAddress/editAddress?newsid=' + newsid
      // 跳转到商品详情
    })
  },
  goEditAddress: function () {//跳转地址页面
    wx.navigateTo({
      url: '../editAddress/editAddress'
    })
  },
  addressAllShow: function () {//地址选择显示
    this.setData({
      addressSelectBtn: false
    });
  },
  addressAllHide: function () {//地址选择隐藏
    this.setData({
      addressSelectBtn: true
    });
  },    
  run1: function () {
    var vm = this;
    var interval = setInterval(function () {
      if (-vm.data.marqueeDistance < vm.data.length) {
        vm.setData({
          marqueeDistance: vm.data.marqueeDistance - vm.data.marqueePace,
        });
      } else {
        clearInterval(interval);
        vm.setData({
          marqueeDistance: vm.data.windowWidth
        });
        vm.run1();
      }
    }, vm.data.interval);
  },
  run2: function () {
    var vm = this;
    var interval = setInterval(function () {
      if (-vm.data.marqueeDistance2 < vm.data.length) {
        // 如果文字滚动到出现marquee2_margin=30px的白边，就接着显示
        vm.setData({
          marqueeDistance2: vm.data.marqueeDistance2 - vm.data.marqueePace,
          marquee2copy_status: vm.data.length + vm.data.marqueeDistance2 <= vm.data.windowWidth + vm.data.marquee2_margin,
        });
      } else {
        if (-vm.data.marqueeDistance2 >= vm.data.marquee2_margin) { // 当第二条文字滚动到最左边时
          vm.setData({
            marqueeDistance2: vm.data.marquee2_margin // 直接重新滚动
          });
          clearInterval(interval);
          vm.run2();
        } else {
          clearInterval(interval);
          vm.setData({
            marqueeDistance2: -vm.data.windowWidth
          });
          vm.run2();
        }
      }
    }, vm.data.interval);
  },


  gotoDnmodel: function (e) { //选择天数
    this.setData({
      zhouqiSelect: e.detail.value,
      dnmodel_note: jisuan.dnmodel[e.detail.value].note,
      milkingSelectDay: e.detail.value == 7 ? 1 : this.data.dn.TotalDays,
      'dn.dnmodel': jisuan.dnmodel[e.detail.value],
      'dn.zhouqi': e.detail.value,
      'dn.jgts': e.detail.value == 1 ? 1 : (e.detail.value == 2 ? 2 : (e.detail.value == 3 ? 1 : (e.detail.value == 4 ? 1 : 0))),
    })
    this.countSum();
    this.noStock();
    this.dnJisuan()
  },
  gotoTs: function (e) { //选择天数
    // console.log('radio发生change事件，携带的value值为：', e.detail.value)
    this.setData({
      milkingSelectDay: Number(e.detail.value) > this.data.dn.mints ? e.detail.value : this.data.dn.mints,
      'dn.TotalDays': Number(e.detail.value) > this.data.dn.mints ? e.detail.value : Number(this.data.dn.mints),
      'dn.ishuodong': false,
      'dn.ists': true,
      'dn.isksrq': false,
      'dn.isjzrq': false,
    })
    this.countSum();
    this.noStock();
    this.dnJisuan()
  },
  godeliveryMethod: function (e) { //选择配送方式20200427
    this.setData({
      deliveryMethodSelect: e.detail.value,
    })
  },

  add: function (e) {
    // 加
    var count = this.data.specification;
    if (count.num < count.stock) {
      count.num++
    } else {
      count.num == count.stock;
    }
    count.priceSum = (count.num * count.price).toFixed(2);
    this.setData({
      specification: count,
      'dn.Count': count.num
    });
    this.countSum();
    this.noStock();
  },
  minus: function (e) {
    // 减
    var count = this.data.specification;
    if (count.num <= 1) {
      count.num = 1
    } else {
      count.num--;
    }
    count.priceSum = (count.num * count.price).toFixed(2);
    this.setData({
      specification: count,
      'dn.Count': count.num
    })
    this.countSum();
    this.noStock();
  },
  countSum: function () {
    // 总价
    var count = this.data.specification;
    var milkingSelectDay = this.data.milkingSelectDay;
    count.priceSumday = (count.priceSum * milkingSelectDay).toFixed(2);
    this.setData({
      specification: count,
      'dn.je': count.priceSumday
    })
  },
  milkingTimer: function (e) { //选择送奶时间
    //console.log('radio发生change事件，携带的value值为：', e.detail.value)
    this.setData({
      'dn.snsd': e.detail.value
    })
  },



  gotoKsrq: function (e) { //20200213获取开始日期
    var ksrq = e.detail.value
    var jsrq = jisuan.DateAdd('day', this.data.milkingSelectDay, ksrq) //this.data.dn.tdrq
    // if (ksrq > jsrq) {
    //   wx.showToast({
    //     title: '抱歉，配送开始日期不能大于结束日期！',
    //     icon: 'none',
    //     duration: 2000
    //   })
    //   e.detail.value = this.data.dn.qdrq
    // }
    this.setData({
      'dn.qdrq': e.detail.value,
      'dn.tdrq': jsrq,
      'dn.ishuodong': false,
      'dn.ists': false,
      'dn.isksrq': true,
      'dn.isjzrq': false,
      //years: e.detail.value.substring(0, 4),
      //months: e.detail.value.substring(5, 7),
      //days: e.detail.value.substring(8, 11)
    })
    this.dnJisuan()
  },
  gotoJzrq: function (e) { //20200214获取结束日期
    //console.log('picker发送选择改变，携带值为', e.detail.value)
    var jsrq = e.detail.value
    var dnts = Number(-this.data.spinfo.syspars.mints)
    var ksrq = jisuan.DateAdd('day', dnts, jsrq)
    console.log(ksrq)
    if (jisuan.GetDateObject(this.data.spinfo.syspars.minksrq) > ksrq) {
      wx.showToast({
        title: '抱歉，配送开始日期不能大于结束日期！',
        icon: 'none',
        duration: 2000
      })
      e.detail.value = jisuan.formatDate(jisuan.DateAdd('day', Number(this.data.spinfo.syspars.mints), this.data.spinfo.syspars.minksrq))
    }

    this.setData({
      'dn.tdrq': e.detail.value,
      'dn.ishuodong': false,
      'dn.ists': false,
      'dn.isksrq': false,
      'dn.isjzrq': true,
    })
    this.dnJisuan()
    this.setData({
      milkingSelectDay: this.data.dn.TotalDays,
    })
  },

  // vouchersRadio: function (e) { //选择代金券
  //   console.log('radio发生change事件，携带的value值为：', e.detail.value)
  //   this.setData({
  //     hdindex: e.detail.value
  //   })
  // },
  modeBorderClick: function () {//到期提醒显示

    var vm = this;
    var length = vm.data.text.length * vm.data.size;//文字长度
    var windowWidth = wx.getSystemInfoSync().windowWidth;// 屏幕宽度
    vm.setData({
      modeBorderClick: false,
      length: length,
      windowWidth: windowWidth,
      marquee2_margin: length < windowWidth ? windowWidth - length : vm.data.marquee2_margin//当文字长度小于屏幕长度时，需要增加补白
    });
    vm.run1();// 水平一行字滚动完了再按照原来的方向滚动
    vm.run2();// 第一个字消失后立即从右边出现    
  },
  // 确认订单支付隐藏
  goZhiFuFormHide: function () {
    this.setData({
      formSumbitHidden: true
    })
  },
  productSelectSp:function(e){//选择产品
   
    var index = e.currentTarget.dataset.index;
    var productSelectSp = this.productSelectSp;
    var count = this.data.count
   var productSelectSp_image = count[index].productImg;
   var productSelectSp_name = count[index].nameProduct
   var productSelectSp_price = count[index].danjia
    this.setData({
      productSelectSp_image: productSelectSp_image,
      productSelectSp_name: productSelectSp_name,
      productSelectSp_price: productSelectSp_price,
      formSumbitHidden: false,
      scrollTopproductSelect:0,//回到顶部
    });
   

  },
    tuijianData: function (e) { //选择推荐日期选择20210311
    // console.log('radio发生change事件，携带的value值为：', e.detail.value)
    this.setData({
      tuijianDataIndex: e.detail.value
    })
  }, 
  goTabBar: function (event) {
    var newsid = event.currentTarget.dataset.newsid;
    wx.redirectTo({
      url: newsid
      // 跳转tabBar
    })
  },   
})